﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_StandardValue.cs
* 创建标识：曾乃强 15158756652 2011-03-17 11:03:01
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_StandardValue*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_StandardValue
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        public int Insert(Model.CNVP_StandardValue obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "StandardValue ([StandardID],[StandardValueName],[StandardValueOtherName],[OrderID],[StandardValuePic])");
            sql.Append("values(@StandardID,@StandardValueName,@StandardValueOtherName,@OrderID,@StandardValuePic)");
            sql.Append(";SELECT @@IDENTITY");
            SqlParameter[] pra = {
                            new SqlParameter("@StandardID",obj.StandardID),
							new SqlParameter("@StandardValueName",obj.StandardValueName),
							new SqlParameter("@StandardValueOtherName",obj.StandardValueOtherName),
							new SqlParameter("@OrderID",obj.OrderID),
                            new SqlParameter("@StandardValuePic",obj.StandardValuePic)
                                 };
            return Convert.ToInt32(DbHelper.ExecuteScalar(sql.ToString(), pra));
        }

        public int Update(Model.CNVP_StandardValue obj)
        {
             StringBuilder sql = new StringBuilder();
             sql.Append("update " + Prefix + "StandardValue set [StandardID] = @StandardID,[StandardValueName] = @StandardValueName,[StandardValueOtherName] = @StandardValueOtherName,[OrderID] = @OrderID,[StandardValuePic]=@StandardValuePic where [ID] = @ID");

            SqlParameter[] pra = { 
                            new SqlParameter("@ID",obj.ID),
							new SqlParameter("@StandardID",obj.StandardID),
							new SqlParameter("@StandardValueName",obj.StandardValueName),
							new SqlParameter("@StandardValueOtherName",obj.StandardValueOtherName),
							new SqlParameter("@OrderID",obj.OrderID),
                            new SqlParameter("@StandardValuePic",obj.StandardValuePic)
                                };
             return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public int Delete(Model.CNVP_StandardValue obj)
        {
           StringBuilder sql = new StringBuilder();
           sql.Append("delete from " + Prefix + "StandardValue where [ID] = @ID");
           SqlParameter[] pra = {
                                new SqlParameter("@ID",obj.ID)
						
                                };
           return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }


        public Model.CNVP_StandardValue LoadById(int ID)
        {
            
            StringBuilder sql = new StringBuilder();
            sql.Append("select [StandardID],[StandardValueName],[StandardValueOtherName],[OrderID],[StandardValuePic] from " + Prefix + "StandardValue");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra); 
            Model.CNVP_StandardValue cnvp_standardvalue = new Model.CNVP_StandardValue();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_standardvalue.StandardID = dr["StandardID"] is DBNull ? 0 : (int)dr["StandardID"];
                cnvp_standardvalue.StandardValueName = dr["StandardValueName"] is DBNull ? String.Empty : (string)dr["StandardValueName"];
                cnvp_standardvalue.StandardValueOtherName = dr["StandardValueOtherName"] is DBNull ? String.Empty : (string)dr["StandardValueOtherName"];
                cnvp_standardvalue.OrderID = dr["OrderID"] is DBNull ? 0 : (int)dr["OrderID"];
                cnvp_standardvalue.StandardValuePic = dr["StandardValuePic"] is DBNull ? String.Empty : (string)dr["StandardValuePic"];
            }
            return cnvp_standardvalue;
        }

        #endregion

        public List<Model.CNVP_StandardValue> LoadAll(int StandardID)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[StandardValueName],[StandardValueOtherName],[OrderID],[StandardValuePic] from " + Prefix + "StandardValue");
            sql.Append(" where [StandardID] = @StandardID order by OrderID");
            SqlParameter[] pra = {
                                 new SqlParameter("@StandardID",StandardID)
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            List<Model.CNVP_StandardValue> list = new List<Model.CNVP_StandardValue>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_StandardValue cnvp_standardvalue = new Model.CNVP_StandardValue();
                    cnvp_standardvalue.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_standardvalue.StandardValueName = dr["StandardValueName"] is DBNull ? String.Empty : (string)dr["StandardValueName"];
                    cnvp_standardvalue.StandardValueOtherName = dr["StandardValueOtherName"] is DBNull ? String.Empty : (string)dr["StandardValueOtherName"];
                    cnvp_standardvalue.OrderID = dr["OrderID"] is DBNull ? 0 : (int)dr["OrderID"];
                    cnvp_standardvalue.StandardValuePic = dr["StandardValuePic"] is DBNull ? String.Empty : (string)dr["StandardValuePic"];
                    list.Add(cnvp_standardvalue);
                }
            }
            return list;
        }

        public int DeleteNotIn(int StandardID, string nowid)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from " + Prefix + "StandardValue where [StandardID]=" + StandardID + " and [ID] not in (" + nowid + ")");
            return DbHelper.ExecuteNonQuery(sql.ToString());
        }

        public List<Model.CNVP_StandardValue> StandardValueLoadNotIn(int StandardID, string nowid)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[StandardValueName],[StandardValueOtherName],[OrderID],[StandardValuePic] from " + Prefix + "StandardValue");
            sql.Append(" where [StandardID] = @StandardID and [ID] not in (" + nowid + ")");
            SqlParameter[] pra = {
                                 new SqlParameter("@StandardID",StandardID)
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(), pra);
            List<Model.CNVP_StandardValue> list = new List<Model.CNVP_StandardValue>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_StandardValue cnvp_standardvalue = new Model.CNVP_StandardValue();
                    cnvp_standardvalue.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_standardvalue.StandardValueName = dr["StandardValueName"] is DBNull ? String.Empty : (string)dr["StandardValueName"];
                    cnvp_standardvalue.StandardValueOtherName = dr["StandardValueOtherName"] is DBNull ? String.Empty : (string)dr["StandardValueOtherName"];
                    cnvp_standardvalue.OrderID = dr["OrderID"] is DBNull ? 0 : (int)dr["OrderID"];
                    cnvp_standardvalue.StandardValuePic = dr["StandardValuePic"] is DBNull ? String.Empty : (string)dr["StandardValuePic"];
                    list.Add(cnvp_standardvalue);
                }
            }
            return list;
        }
    }
}

